<template>
	<div class="page-wrap">
		<page-title></page-title>
		<div class="back">
			<el-button @click="goback" type="primary" size="small">返回</el-button>
		</div>
		<div class="page-content">
			<div class="page-row">
				<div class="box-right">
					<div class="table-box">
						<el-tabs v-model="activeTab" class="flex-tabs">
							<el-tab-pane
								:disabled="this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE' "
								name="1"
								label="花费设置"
								lazy
							>
								<spendSet
									ref="spend"
									:basicDataF="this.basicData"
									v-on:changeActiveTab="changeActive($event)"
								></spendSet>
							</el-tab-pane>
							<el-tab-pane
								name="2"
								:disabled="this.showactiveTab < 2 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="去污设置"
								lazy
							>
								<decontaSet :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></decontaSet>
							</el-tab-pane>
							<el-tab-pane
								name="3"
								:disabled="this.showactiveTab < 3 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="风化参数设置"
								lazy
							>
								<weatheringSet :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></weatheringSet>
							</el-tab-pane>
							<el-tab-pane
								name="4"
								:disabled="this.showactiveTab < 4 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="区域特征参数设置"
								lazy
							>
								<areaSet :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></areaSet>
							</el-tab-pane>
							<el-tab-pane
								name="5"
								:disabled="this.showactiveTab < 5 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="器官剂量设置"
								lazy
							>
								<organDosageSet :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></organDosageSet>
							</el-tab-pane>
							<el-tab-pane
								name="6"
								:disabled="this.showactiveTab < 6 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="饮用水"
								lazy
							>
								<drinkingwater :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></drinkingwater>
							</el-tab-pane>
							<el-tab-pane
								name="7"
								:disabled="this.showactiveTab < 7 || this.basic_Data.OCENDAT1001=='TRUE' ||this.early_Data.MIENDAT2001=='TRUE'"
								label="输出设置"
								lazy
							>
								<outputSet :basicDataF="this.basicData" v-on:changeActiveTab="changeActive($event)"></outputSet>
							</el-tab-pane>
						</el-tabs>
					</div>
				</div>
			</div>
		</div>
	</div>
</template>

<script>
import spendSet from "./spendSet.vue"
import decontaSet from "./decontaSet.vue"
import weatheringSet from "./weatheringSet.vue"
import areaSet from "./areaSet.vue"
import organDosageSet from "./organDosageSet"
import drinkingwater from "./drinkingwater"
import outputSet from "./outputSet.vue"
import { mapState } from "vuex"
export default {
	components: {
		spendSet,
		decontaSet,
		weatheringSet,
		areaSet,
		organDosageSet,
		drinkingwater,
		outputSet,
	},
	data() {
		return {
			activeTab: "1",
			basicData: {
				GENUMRAD001: "",
				id: "1",
				zaoqiList: [],
				aiZhengList: [],
				ISOTPGRP_NAM: [],
				MIORGDEF_ORG: [],
				PDPOPFLG001: "",
				OCENDAT1001: "",
				MIENDAT2001: "",
				MIORGDEF_ORG1: [],
				MIORGDEF_ORG2: [],
			},
		}
	},
	computed: {
		...mapState({
			showactiveTab: (state) => state.token.longterm_show_Tab,
			basic_Data: (state) => state.token.basic_Data,
			early_Data: (state) => state.token.early_Data,
			longterm_Data: (state) => state.token.early_Data,
		}),
	},
	created() { 
		this.getBasicData()
		this.getzaoqi()
		this.getearlyData()
		this.getAiZheng()
		this.getlongtermData()
		this.$emit("changeActiveTab", this.activeTab)
		this.$store.dispatch("change_longterm_showTab", this.activeTab)
		this.router()
		this.getMIORGDEF_ORG1()
		this.getMIORGDEF_ORG2()
	},

	methods: {
		//配置面包屑
		router() {
			// let temproute = [...this.$route.query.routeList]
			let temproute = []
			let advert = {
				resrName: "长期模块",
			}
			temproute.push(advert)
			this.$store.commit("updateRoute", temproute)
		},
		goback() {
			this.$router.go(-1)
		},
		getBasicData() {
			//获取基本模块数据
			let params = {
				batchid: this.$route.query.id,
				batchinfo: "BASE",
			}
			// console.log(params)
			this.$appApi
				.BATCH_DETAIL(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						let tempdata = JSON.parse(res.data.substring(8))
						this.$store.dispatch("upData_basic_Data", tempdata) 
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getearlyData() {
			//获取早期模块数据
			let params = {
				batchid: this.$route.query.id,
				batchinfo: "ZAOQI",
			}
			// console.log(params)
			this.$appApi
				.BATCH_DETAIL(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						let tempdata = JSON.parse(res.data.substring(8))
						this.$store.dispatch("upData_early_Data", tempdata)
						this.$refs.spend.setOption()
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getlongtermData() {
			//获取长期模块数据
			let params = {
				batchid: this.$route.query.id,
				batchinfo: "CHANGQI",
			}
			this.$appApi
				.BATCH_DETAIL(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						let tempdata = JSON.parse(res.data.substring(8))
						this.$store.dispatch("change_longterm_showTab", tempdata.SETPAGEINDEX)
						this.$store.dispatch("upData_longterm_Data", tempdata) 
						this.$refs.spend.setData()
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getzaoqi() {
			this.$appApi
				.SS_ZAOQI_SEARCH()
				.then((res) => {
					var str = res.data.substring(8)
					this.basicData.zaoqiList = JSON.parse(str) 
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getAiZheng() {
			this.$appApi
				.SS_AIZHENG_SEARCH()
				.then((res) => {
					var str = res.data.substring(8)
					this.basicData.aiZhengList = JSON.parse(str) 
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getMIORGDEF_ORG2() {
			let params = {
				dictypeid: 2,
			} 
			this.loading = true
			this.$appApi
				.ZD_GET_DICINFOS(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						this.basicData.MIORGDEF_ORG2 = JSON.parse(
							res.data.substring(8)
						) 
						this.loading = false
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		getMIORGDEF_ORG1() {
			let params = {
				dictypeid: 1,
			} 
			this.loading = true
			this.$appApi
				.ZD_GET_DICINFOS(params)
				.then((res) => {
					var str = res.data.substring(0, 1)
					if (str == "E") {
						let message = res.data.substring(6)
						this.$notify.error({
							title: "请求数据失败！",
							message: message,
							type: "success",
						})
					} else if (str == "S") {
						this.basicData.MIORGDEF_ORG1 = JSON.parse(
							res.data.substring(8)
						) 
					}
				})
				.catch((err) => {
					console.log(err)
				})
		},
		changeActive(value) {
			// console.log(value)
			this.activeTab = value
		},
	},
}
</script>